Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore elementwise min/max on SIMD, with explicit naming. #24136

Merged
merged 4 commits into from
Apr 25, 2019

Conversation

stephentyrone
Copy link
Contributor

@stephentyrone stephentyrone commented Apr 18, 2019

Having these as free functions causes expression too complex issues due to overload vis-a-vis min. There are (at least) three plausible solutions:

  1. Fix the typechecker. This is infeasable in the short term; or more precisely, we do not know how much work is involved.

  2. Give these operations different names. Candidates discussed with core team include "pointwiseMin", "elementwiseMin", "lanewiseMin"; these all suffer from the flaw that when someone writes "min" in a SIMD context, they are essentially always looking for either the horizontal minimum (reduction) on a single vector or--more often--the lanewise minimum of two vectors (this operation). It would be odd to give the operation that people actually want the unnecessarily verbose name.

  3. Make these operations static; this is, in effect, a different name, but it's one which frequently allows eliding the qualifier:

let x = v + .min(v, w)

After considerable back-and-forth discussion with core, we settled on pointwiseMin and pointwiseMax. These aren't perfect, but they are explicit, which is worth a lot.

This rounds out SE-0251.

…unctions.

Having these as free functions causes expression too complex issues due to overload vis-a-vis min<Collection>. There are (at least) three plausible solutions:

1. Fix the typechecker. This is infeasable in the short term; or more precisely, we do not know how much work is involved.

2. Give these operations different names. Candidates discussed with core team include "pointwiseMin", "elementwiseMin", "lanewiseMin"; these all suffer from the flaw that when someone writes "min" in a SIMD context, they are essentially always looking for either the horizontal minimum (reduction) on a single vector or--more often--the lanewise minimum of two vectors (this operation). It would be odd to give the operation that people actually want the unnecessarily verbose name.

3. Make these operations static; this is, in effect, a different name, but it's one which frequently allows eliding the qualifier:

  let x = v + .min(v, w)

This isn't perfect; you will still need to spell out SIMD4.min( ) fairly often, but that's more concise than any of the proposed alternatives, and at least allows elision some of the time. Also, if you squint, you can pretend that the "." prefix is like ".<" and ".&" and indicates lanewise operation.
@stephentyrone
Copy link
Contributor Author

@swift-ci please test

@stephentyrone
Copy link
Contributor Author

@swift-ci please test source compatibility

@stephentyrone stephentyrone changed the title Restore elementwise min/max on SIMD, but as statics. Restore elementwise min/max on SIMD, with explicit naming. Apr 24, 2019
@stephentyrone
Copy link
Contributor Author

@swift-ci please test source compatibility

Co-Authored-By: stephentyrone <stephentyrone@gmail.com>
@stephentyrone
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 4b94685

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 8e13ea6

@stephentyrone
Copy link
Contributor Author

Linux failure unrelated (base breakage).

@stephentyrone
Copy link
Contributor Author

@swift-ci please smoke test linux

@stephentyrone stephentyrone merged commit 9850150 into swiftlang:master Apr 25, 2019
@stephentyrone stephentyrone deleted the static-min-max branch April 25, 2019 18:52
stephentyrone added a commit to stephentyrone/swift that referenced this pull request May 14, 2019
…#24136)

* Restore elementwise min/max on SIMD, but as statics instead of free functions.

Having these as free functions causes expression too complex issues due to overload vis-a-vis min<Collection>. There are (at least) three plausible solutions:

1. Fix the typechecker. This is infeasable in the short term; or more precisely, we do not know how much work is involved.

2. Give these operations different names. Candidates discussed with core team include "pointwiseMin", "elementwiseMin", "lanewiseMin"; these all suffer from the flaw that when someone writes "min" in a SIMD context, they are essentially always looking for either the horizontal minimum (reduction) on a single vector or--more often--the lanewise minimum of two vectors (this operation). It would be odd to give the operation that people actually want the unnecessarily verbose name.

3. Make these operations static; this is, in effect, a different name, but it's one which frequently allows eliding the qualifier:

  let x = v + .min(v, w)

This isn't perfect; you will still need to spell out SIMD4.min( ) fairly often, but that's more concise than any of the proposed alternatives, and at least allows elision some of the time. Also, if you squint, you can pretend that the "." prefix is like ".<" and ".&" and indicates lanewise operation.
stephentyrone added a commit that referenced this pull request May 15, 2019
* Restore elementwise min/max on SIMD, with explicit naming. (#24136)

* Restore elementwise min/max on SIMD, but as statics instead of free functions.

Having these as free functions causes expression too complex issues due to overload vis-a-vis min<Collection>. There are (at least) three plausible solutions:

1. Fix the typechecker. This is infeasable in the short term; or more precisely, we do not know how much work is involved.

2. Give these operations different names. Candidates discussed with core team include "pointwiseMin", "elementwiseMin", "lanewiseMin"; these all suffer from the flaw that when someone writes "min" in a SIMD context, they are essentially always looking for either the horizontal minimum (reduction) on a single vector or--more often--the lanewise minimum of two vectors (this operation). It would be odd to give the operation that people actually want the unnecessarily verbose name.

3. Make these operations static; this is, in effect, a different name, but it's one which frequently allows eliding the qualifier:

  let x = v + .min(v, w)

This isn't perfect; you will still need to spell out SIMD4.min( ) fairly often, but that's more concise than any of the proposed alternatives, and at least allows elision some of the time. Also, if you squint, you can pretend that the "." prefix is like ".<" and ".&" and indicates lanewise operation.

* Really remove static min and max on simd. One slipped through. (#24283)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants